package dp_algorithm.nowcoder.medium;

import java.util.Scanner;

/**
 * @author bruin_du
 * @description 计算字符串的编辑距离
 * https://www.nowcoder.com/practice/3959837097c7413a961a135d7104c314?
 * tpId=37&&tqId=21275&rp=1&ru=/activity/oj&qru=/ta/huawei/question-ranking
 * @date 2022/5/20 16:24
 **/
public class LevenshteinDistence {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            String str1 = in.next();
            String str2 = in.next();
            char[] sArr = str1.toCharArray();
            char[] pArr = str2.toCharArray();
            int length1 = str1.length(),length2 = str2.length();
            int[][] dp = new int[length1 + 1][length2 + 1];
            for (int i = 1; i <= length1; i++) {
                dp[i][0] = i;
            }
            for (int j = 1; j <= length2; j++) {
                dp[0][j] = j;
            }
            for (int i = 1; i <= length1; i++) {
                for (int j = 1; j <= length2; j++) {
                    if(sArr[i - 1] == pArr[j - 1])
                        dp[i][j] = dp[i - 1][j - 1];
                    else{
                        dp[i][j] = Math.min(dp[i - 1][j],Math.min(dp[i][j - 1],dp[i - 1][j - 1])) + 1;
                    }
                }
            }
            System.out.println(dp[length1][length2]);
        }
    }
}
